package plan.parser.classes;

public class Time {

	int hour;
	int minute;
	static char dot='.';
	
	public Time(String time) {
		
		if (isTime(time))
		{
			int dotIndex=time.indexOf(dot);
		
			hour = Integer.valueOf(time.substring(0,dotIndex));
			minute = Integer.valueOf(time.substring(dotIndex+1));
		}
	}
	
	@Override
	public String toString() {
		return Integer.toString(hour)+dot+Integer.toString(minute);
	}
	
	@Override 
	public boolean equals(Object obj){
		if (this == obj)
	           return true;
	       if (obj == null)
	           return false;
	       if (getClass() != obj.getClass())
	           return false;
	       final Time other = (Time) obj;
	       if (hour != other.hour)
	           return false;
	       if (minute != other.minute)
	           return false;
	       return true;
	}

	public static boolean isTime(String symbol) {
		int dotIndex;
		if (symbol==null)
			return false;
		if ((dotIndex=symbol.indexOf(dot))<0)
			return false;
		try {
			Integer.parseInt(symbol.substring(0,dotIndex));
			Integer.parseInt(symbol.substring(dotIndex+1));
		}
		catch (Exception e) {
			return false;
		}
		return true;
	}
}
